package rong.common.action.web.admin.resource;

import java.util.List;

import javax.annotation.Resource;

import rong.common.entity.Link;
import rong.common.service.LinkService;
import rong.common.utils.CRUDAction;

public class LinkAction extends CRUDAction {

	private static final long serialVersionUID = 3567683754156288730L;

	@Resource
	private LinkService linkService;
	
	private Link link = new Link();
	private List<Link> links;
	
	public Object getModel() {
		return (null != links ? links : link);
	}
	
	@Override
	public String delete() throws Exception {
		linkService.deleteLink(link.getId());
		return RELOAD;
	}

	@Override
	public String input() throws Exception {
		if(null==link.getId() || 0==link.getId()){
			//...
		}else{
			link = linkService.queryById(link.getId());
		}
		return INPUT;
	}

	@Override
	public String list() throws Exception {
		links = linkService.queryAll();
		return SUCCESS;
	}

	@Override
	public String save() throws Exception {
		if(null==link.getId()||0==link.getId()){
			linkService.saveLink(link);
		}else{
			linkService.updateLink(link);
		}
		return RELOAD;
	}

}
